package com.gitee.wsl.compose.ui.snackbar

import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Snackbar
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.gitee.wsl.compose.ui.base.SnackBar
import com.gitee.wsl.compose.ui.container.CircleBoxScopeInstance.align


/**
 * To show an error SnackBar with retry button at bottom of the screen.
 */
@Composable
fun SnackBar.Error(
    syncFailedReason: String,
    retryString: String = "Retry",
    onRetryClicked: (() -> Unit)? = null,
) {
    Snackbar(
        modifier = Modifier
            .padding(10.dp)
            .align(Alignment.BottomCenter),
        containerColor = MaterialTheme.colorScheme.surface,
        contentColor = MaterialTheme.colorScheme.onSurface,
        action = {
            if (onRetryClicked != null) {
                TextButton(
                    onClick = onRetryClicked
                ) {
                    Text(retryString)
                }
            }
        }
    ) {
        Text(text = syncFailedReason)
    }
}